package tests;
import java.io.File;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Test;

import conference.Author;
import conference.Conference;
import conference.Manuscript;


public class TestAuthorComparator {
	private Conference conference;
	List<Manuscript> manuscriptList;
	Author author1;
	Author author2;
	Author author3;
	Author author4;
	Manuscript manu1;
	Manuscript manu2;
	Manuscript manu3;
	Manuscript manu4;
	@Before
	public void intializeAuthorComparator() {
		author1 = new Author();
		author2 = new Author();
		author3 = new Author();
		author4 = new Author();
		author1.setFirstName("Alf");
		author1.setLastName("Alpha");
		author2.setFirstName("Zack");
		author2.setLastName("Zulu");
		author3.setFirstName("Bob");
		author3.setLastName("Bravo");
		author4.setFirstName("Bob");
		author4.setLastName("Alpha");
		manu1 = new Manuscript(author1, new File("Man1"),
				"Man1");
		manu2 = new Manuscript(author2, new File("Man1"),
				"Man1");
		manu3 = new Manuscript(author3, new File("Man1"),
				"Man1");
		manu4 = new Manuscript(author4, new File("Man1"),
				"Man1");
		manuscriptList = new ArrayList<Manuscript>();
		manuscriptList.add(new Manuscript(author1, 
				new File("Man1"), "Man1"));
		manuscriptList.add(new Manuscript(author2,
				new File("Man1"), "Man1"));
		manuscriptList.add(new Manuscript(author3, 
				new File("Man1"), "Man1"));
		manuscriptList.add(new Manuscript(author4, 
				new File("Man1"), "Man1"));
		conference = new Conference("Test Con",
				new Date(), 
				new Date(),
				new Date(),
				manuscriptList);
	}
	@Test
	public void testAuthorComparator() {
		// new list should be manu1, manu4, manu3, manu2
		Manuscript[] postSort;
		conference.sortByAuthor();
		postSort = conference.getAllManuscripts();
		assertEquals("First manuscript is not manu1.", 
				manu1.getAuthor(), 
				postSort[0].getAuthor());
		assertEquals("Second manuscript is not manu4.", 
				manu4.getAuthor(), 
				postSort[1].getAuthor());
		assertEquals("Third manuscript is not manu3.", 
				manu3.getAuthor(), 
				postSort[2].getAuthor());
		assertEquals("Fourth manuscript is not manu2.", 
				manu2.getAuthor(), 
				postSort[3].getAuthor());
	}
}
